from django.contrib import admin
from scrumtool.models import FileAttachments, Impediment, ProductBacklogStory
from scrumtool.models import Project, ProjectLogEntry, Sprint, Task

class ProjectAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('name', )}
    list_display = ('name', 'active')
    list_display_links = ('name',)
    list_filter = ('active',)
    search_fields = ('name', 'description')

class ImpedimentAdmin(admin.ModelAdmin):
    list_display = ('project', 'name', 'is_solved')
    list_display_links = ('name',)
    list_filter = ('is_solved', 'project')
    search_fields = ('name', 'description')

class SprintAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('name', )}
    filter_horizontal = ('team',)
    fields = ( ('project', 'name'), 'slug', 'goal', ('start_date', 'end_date'), 'team')
    list_display = ('project', 'name', 'start_date', 'end_date')
    list_display_links = ('name', 'start_date', 'end_date')
    list_filter = ('project', 'end_date')
    search_fields = ('name', )
    date_hierarchy = 'start_date'    

class FileAttachmentsInline(admin.TabularInline):
    model = FileAttachments
    extra = 1

class ProductBacklogStoryAdmin(admin.ModelAdmin):
    model = ProductBacklogStory
    inlines = [FileAttachmentsInline]
    fields = ( ('project', 'sprint'), 'story', 'tags', 'priority', 'story_points', 'description')
    list_display = ('project', 'sprint', 'priority', 'story', 'story_points')
    list_display_links = ('priority', 'story', 'story_points')
    list_filter = ('project', 'sprint')
    search_fields = ('story', )    

class TaskAdmin(admin.ModelAdmin):
    fields = ( 'backlog_story', ('order', 'name'), ('hours', 'responsible'))
    list_display = ('backlog_story', 'order', 'name', 'hours', 'responsible')
    list_display_links = ('order', 'name', 'hours')
    list_filter = ('responsible', 'backlog_story')
    search_fields = ('name', )

class ProjectLogEntryAdmin(admin.ModelAdmin):
    list_display = ('action_time', 'change_message', 'project', 'user')
    list_display_links = ('change_message',)
    list_filter = ('project', 'user')
    search_fields = ('change_message', )

admin.site.register(Project, ProjectAdmin)
admin.site.register(Impediment, ImpedimentAdmin)
admin.site.register(Sprint, SprintAdmin)
admin.site.register(ProductBacklogStory, ProductBacklogStoryAdmin)
admin.site.register(Task, TaskAdmin)
admin.site.register(ProjectLogEntry, ProjectLogEntryAdmin)
